
#include "../lexerparser/lp_defs.h"
#include "../literalparsing/literals.h"


void test_lexer(char * data)
{
 current_filename=data;
 FILE * in=fopen(data,"rb");
 initAction(in);
 int type;
#define PRINT_KEYWORD(TYPE)   if (type==TYPE) printf("%d,%d: KEYWORD - %s\n",yylloc.first_line, yylloc.first_column,#TYPE);
#define PRINT_KEYOP(TYPE,VAL) if (type==TYPE) printf("%d,%d: TOKEN(\"%s\")\n",yylloc.first_line, yylloc.first_column,#VAL);
 do
 {
   type=yylex();
   if (type==END_OF_FILE) printf("%d,%d: End of file\n",yylloc.first_line, yylloc.first_column);
   if (type==IDENTIFIER)  printf("%d,%d: Identifier(\"%s\")\n",yylloc.first_line, yylloc.first_column,yylval.m_strg->c_str());
   if (type==INTEGER)     { printf("%d,%d: INTEGER(",yylloc.first_line, yylloc.first_column); printf(LL,yylval.m_intl); printf(")\n"); }
   if (type==INSTRUCTION_DELIMITER) printf("%d,%d: Delimiter\n",yylloc.first_line, yylloc.first_column);
   if (type==STRING_LITERAL)        printf("%d,%d: STRING(\"%s\")\n",yylloc.first_line, yylloc.first_column,yylval.m_strg->c_str());
   if (type==REAL)                  printf("%d,%d: REAL(\"%lf\")\n",yylloc.first_line, yylloc.first_column,yylval.m_real); 
   if (type==_CHAR)                  printf("%d,%d: CHAR(\'%s\')\n",yylloc.first_line, yylloc.first_column,yylval.m_strg->c_str());
   if (type==_BOOL)                  printf("%d,%d: BOOL(\'%s\')\n",yylloc.first_line, yylloc.first_column,(yylval.m_bool)?"true":"false");
   PRINT_KEYWORD(END_DECL)
   PRINT_KEYWORD(CLASS)
   PRINT_KEYWORD(DEFERRED)
   PRINT_KEYWORD(FROZEN)
   PRINT_KEYWORD(FEATURE)
   PRINT_KEYWORD(ALIAS)
   PRINT_KEYWORD(CONVERT)
   PRINT_KEYWORD(INHERIT)
   PRINT_KEYWORD(RENAME)
   PRINT_KEYWORD(AS)
   PRINT_KEYWORD(DO)
   PRINT_KEYWORD(LOCAL)
   PRINT_KEYWORD(THEN)
   PRINT_KEYWORD(ELSE)
   PRINT_KEYWORD(REDEFINE)
   PRINT_KEYWORD(UNDEFINE)
   PRINT_KEYWORD(CREATE) 
   PRINT_KEYWORD(IF)
   PRINT_KEYWORD(SELECT)    
   PRINT_KEYWORD(FROM)
   PRINT_KEYWORD(LOOP)
   PRINT_KEYWORD(UNTIL)      
   PRINT_KEYOP(TWO_BACKSLASHES,"//")
   PRINT_KEYOP(TWO_SLASHES,"\\")
   PRINT_KEYOP(TWO_DOTS,"..")
   PRINT_KEYOP(GEQ,">=")
   PRINT_KEYOP(LEQ,"<=")
   PRINT_KEYWORD(NOT)
   PRINT_KEYWORD(OR)
   PRINT_KEYWORD(XOR)
   PRINT_KEYWORD(AND)
   PRINT_KEYWORD(AND_THEN)
   PRINT_KEYWORD(OR_ELSE)
   PRINT_KEYWORD(IMPLIES)
   PRINT_KEYWORD(ELSEIF)
   PRINT_KEYOP(NEQ,"/=")
   PRINT_KEYOP(NTILDA,"/~")
   PRINT_KEYOP(ASSIGNMENT,":=")
   PRINT_KEYOP(LEFT_ARRAY,"<<")
   PRINT_KEYOP(RIGHT_ARRAY,">>")
   if (type==';' || type==',' || type==':' || type=='=' || type=='(' || type==')' || type=='[' || type==']'
       || type=='+' || type=='-' || type=='*' || type=='/' || type=='^' || type=='<' || type=='>'
	   || type=='?' || type=='!' || type=='.' || type=='~' || type=='$' || type=='{' || type=='}')
     printf("%d, %d: TOKEN('%c')\n",yylloc.first_line, yylloc.first_column,type);
 } while(type!=END_OF_FILE);
 endAction();
}
